import matplotlib.pyplot as plt

# 设置字体和负号显示
plt.rcParams['font.sans-serif'] = ['SimHei']  # 使用黑体
plt.rcParams['axes.unicode_minus'] = False  # 解决负号显示问题

# 数据
years = list(range(2010, 2023))  # 年份列表
wheat = [3648.7, 3703.37, 3759.26, 3831.41, 3924.81, 4034.78, 4068, 4083.87, 4058.59, 4001.75, 3934.43, 3994.03, 4003.55]
corn = [3247.45, 3370.58, 3476.55, 3663.09, 3828.59, 3943.81, 4059.33, 4000.12, 3934.68, 3846.47, 3871.09, 3897.01, 3880.26]
soybean = [156.41, 154.71, 146.36, 144.04, 147.53, 129.67, 124.67, 119.55, 153.52, 183.53, 188.67, 182.82, 214.96]
peanut = [793.96, 777.44, 766.9, 764.42, 739.47, 722.84, 718.96, 709.23, 695.28, 666.49, 650.86, 631.74, 609.76]


# 创建图表
plt.subplots()

# 绘制每种作物的产量
plt.plot(years, wheat, marker='^', linestyle='-', color='black', label='Wheat')
plt.plot(years, corn, marker='s', linestyle='--', color='black', label='Corn')
plt.plot(years, soybean, marker='D', linestyle='-.', color='black', label='Soybean')
plt.plot(years, peanut, marker='o', linestyle=':', color='black', label='Peanut')

# 添加标题和标签
plt.xlabel('Year')
plt.ylabel('Area (hectares in thousands)')

# 显示图例，并放在右上角
plt.legend(loc='upper right', bbox_to_anchor=(1, 0.8), borderpad=1)

# 显示网格
# plt.grid(True)
plt.savefig("面积.png", bbox_inches='tight', dpi=300)  # 设置 dpi 为 300，图片分辨率更高


# 显示图表
plt.show()
